import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
 export const patientStorage = defineStore('patientStorage',()=>{
    const patient=ref({
        registerId:0,
        orderNo:null,
        realName:null,
        age:0,
        gender:null,
        identifyNumber:null,
    });
    const patientList=ref([]);
    const addPatient= (patientInfo:any)=>{
        patientList.value.push(patientInfo);
    }
 
    const setPatient = (newPatient) => {
        patient.value = {
            registerId: newPatient.registerId || 0,
            orderNo: newPatient.orderNo || null,
            realName: newPatient.realName || null,
            age: newPatient.age || 0,
            gender: newPatient.gender || null,
            identifyNumber: newPatient.identifyNumber || null,
        };
    
        // 强制更新 sessionStorage
        storage();
    };
    
    // storage 函数
    const storage = () => {
        sessionStorage.setItem('Patient', JSON.stringify(patient.value)); // 使用 patient.value
    };
    
    
    return {
        patient,
        patientList,
        addPatient,
      setPatient
      
    }
 })                       